﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace StockTrader.FrontEnd.MarketSummary.DAL
{
    public partial class DataConvertion : Form
    {
        private frmMain _parent;

        public DataConvertion(frmMain main)
        {
            InitializeComponent();
            _parent = main;

        }

        private void DataConvertion_Load(object sender, EventArgs e)
        {

        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                DALclient dac = new DALclient();
                string file = txtFileName.Text;
                DateTime transDate = dtSelected.Value;
                this.Close();
                //dac.DeleteBackupAllMarket(transDate);
                _parent.ConvertData(transDate.Date, file, file);
                //dac.InsertHoseMarketFromRawData(transDate.Date);
            }
            catch
            {
                MessageBox.Show("Import fail, please try again.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }     
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Market file (*.xls)|*.xls"; dialog.InitialDirectory = "c:\\";
            dialog.Title = "Select data file to import ...";
            if (dialog.ShowDialog() == DialogResult.OK)
                txtFileName.Text = dialog.FileName;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
